﻿require.config({
	urlArgs: "version=20170407",
    paths: {
        'jquery': 'packages/jquery',
        'boottree': 'packages/schem-treeview',
        'bootstrap': '../bootstrap/js/bootstrap.min'
    },
    shim: {
        'bootstrap': {
            deps: ['jquery'],
            exports: 'bootstrap'
        },
    	'boottree':{
    		deps:['jquery'],
    		exports: 'boottree'
    	}
    }
});

require(['jquery', 'boottree','bootstrap'],function($){
	var perms_list={};
	var account_id=0;
	var account_name="";
	var timeout;
	var renamebtn_bool = false;
	var submitmbtn_bool = false;
	var deletebtn_bool = false;
	var editmap_bool = false;
	var treeshow_bool = false;
	$.ajax({
		type : 'POST',
		url : '/users/getId',
		//data : jsonda,
	    cache: false,
		async:false,
		//contentType: "application/json; charset=utf-8",
		dataType : 'json',
		success : function(res) {
			if (res.status == 200) {
					account_id=res.data.id;
					account_name=res.data.name;
					document.getElementById("user-info").innerHTML="&nbsp"+res.data.name;
			} else
				alert("加载失败！");
		},
		error : function(xml, err, throwInfo) {
			alert(err);
		}
    });
	$.ajax({
		type : 'POST',
		url : '/users/getPermList',
		//data : jsonda,
	    cache: false,
		async:false,
		//contentType: "application/json; charset=utf-8",
		dataType : 'json',
		success : function(res) {
			if (res.status == 200) {
				perms_list=res.entries;
			} else
				alert("加载失败！");
		},
		error : function(xml, err, throwInfo) {
			alert(err);
		}
    });
	
	setPage();
	getTree();
	getSubmitTree();
	function getSubmitTree(){
		if(window.location.pathname=='/admin/selfmlib.html'){
			$('#submit-tree').innerHTML="";
			var jsondafile={};
			jsondafile.parent_id=0;
			jsondafile.account_id=account_id;
			jsondafile.type="0";
			jsondafile.state="1";
			$.ajax({
				type : 'GET',
				url : '/files/tree',
				data : jsondafile,
			    cache: false,
				async:false,
				contentType: "application/json; charset=utf-8",
				dataType : 'json',
				success : function(res) {
					if (res.status == 200) {
						//循环遍历json，并将其加入显示中
						var treeData=""+JSON.stringify(res.data.nodes)+"";
						
						var defaultData = [
						                   {
						                	 id:'filelist-0',
						                	 text: '素材库',
						                     nodes: JSON.parse(treeData)
						                   }
						                 ];		
						$('#submit-tree').treeview({
					         color: "#428bca",
					         rootable:false,
					         expandIcon: 'glyphicon glyphicon-chevron-right',
					         collapseIcon: 'glyphicon glyphicon-chevron-down',
					         nodeIcon: 'glyphicon glyphicon-bookmark',
					         data:  defaultData
					    });
						
					} else
						alert("加载失败！");
				},
				error : function(xml, err, throwInfo) {
					alert(err);
				}
		    });
		}
	} 
	function setPage(){
		var files_create = false;
		var schems_create = false;
		var currsearch_create = false;	
		for(var i in perms_list){
			var perm_list = perms_list[i];
			if(perm_list.Ename=="files：create"){
				files_create=true;
			}else if(perm_list.Ename=="schems：create"){
				schems_create=true;
			}
		}
		if(files_create){
			$("#file-plus")[0].style.display="";
		}
		if(schems_create){
			$("#schem-plus")[0].style.display="";
		}
		
	}

	function getTree(){
		if(window.location.pathname=='/admin/selfmlib.html'||window.location.pathname=='/admin/plib.html'){
			$('#treeview5').innerHTML="";
			var jsondafile={};
			if(window.location.pathname=='/admin/selfmlib.html'){
				jsondafile.parent_id=0;
				jsondafile.account_id=account_id;
				jsondafile.type="0";
				jsondafile.state="0";
			}
			$.ajax({
				type : 'GET',
				url : '/files/tree',
				data : jsondafile,
			    cache: false,
				async:false,
				contentType: "application/json; charset=utf-8",
				dataType : 'json',
				success : function(res) {
					if (res.status == 200) {
						//循环遍历json，并将其加入显示中
						var treeData=""+JSON.stringify(res.data.nodes)+"";
						var defaultData = [];
						if(!!perms_list){
							for(var i in perms_list){
								var perm_list = perms_list[i];
								if(perm_list.Ename=="admin：selfplib"){
									defaultData.push({
					                	 id:'filelist-h0',
					                	 text: '我的方案',
					                   });
								}
								if(perm_list.Ename=="admin：selfmlib"){
									defaultData.push({
				                   		id:'filelist-0',
						            	text: '我的素材',
						            	nodes: JSON.parse(treeData),
					                	//selectable: false,
					                 });
								}
								if(perm_list.Ename=="admin：mlib"){
									defaultData.push({
				                   		id:'filelist-s0',
						            	text: '素材库',
					                 });
								}
								if(perm_list.Ename=="admin：plib"){
									defaultData.push({
						            	 id:'filelist-t0',
						            	 text: '案例库',
					                 });
								}
								if(perm_list.Ename=="admin：useradmin"){
									defaultData.push({
						                 id:'filelist-e0',
						                 text: '用户管理',
						             });
								}
								if(perm_list.Ename=="admin：roleadmin"){
									defaultData.push({
								         id:'filelist-n0',
								         text: '角色管理',
								    });
								}
								if(perm_list.Ename=="schems：reroot"){
									renamebtn_bool=true;
								}else if(perm_list.Ename=="schems：submitp"&&window.location.pathname=='/admin/selfplib.html'){
									submitmbtn_bool=true;
								}else if(perm_list.Ename=="schems：movep"&&window.location.pathname=='/admin/plib.html'){
									submitmbtn_bool=true;
								}else if(perm_list.Ename=="terms：submitm"&&window.location.pathname=='/admin/selfmlib.html'){
									submitmbtn_bool=true;
								}else if(perm_list.Ename=="schems：deletesp"&&window.location.pathname=='/admin/selfplib.html'){
									deletebtn_bool=true;
								}else if(perm_list.Ename=="schems：deletep"&&window.location.pathname=='/admin/plib.html'){
									deletebtn_bool=true;
								}else if(perm_list.Ename=="schems：deletesm"&&window.location.pathname=='/admin/selfmlib.html'){
									deletebtn_bool=true;
								}else if(perm_list.Ename=="schems：editmapsp"&&window.location.pathname=='/admin/selfplib.html'){
									editmap_bool=true;
								}else if(perm_list.Ename=="schems：editmapsm"&&window.location.pathname=='/admin/selfmlib.html'){
									editmap_bool=true;
								}else if(perm_list.Ename=="schems：editmapp"&&window.location.pathname=='/admin/plib.html'){
									editmap_bool=true;
								}
								
								
							}
							defaultData.push({
							      id:'filelist-w0',
							      text: '个人中心',
							 });
						}
						$('#treeview5').treeview({
					         color: "#41464B",
					         selectedBackColor:"#41464B",
					         expandIcon: 'glyphicon glyphicon-chevron-right',
					         collapseIcon: 'glyphicon glyphicon-chevron-down',
					         nodeIcon: 'glyphicon',
					         data:  defaultData
					    });
						
					} else
						alert("加载失败！");
				},
				error : function(xml, err, throwInfo) {
					alert(err);
				}
		    });
		}
	} 
	var show_id=null;
	//selfresize();
	$('#user-info').mouseover(function(){
		document.getElementById("user-info").innerHTML="&nbsp"+"退出登录";
	});
	$('#user-info').mouseleave(function(){
		document.getElementById("user-info").innerHTML="&nbsp"+account_name;
	});
	$('#user-logout').click(function(){
		$.ajax({
			type : 'GET',
			url : '/logout',
			//data : jsonda,
		    cache: false,
			async:false,
			//contentType: "application/json; charset=utf-8",
			dataType : 'json',
			success : function(res) {
				if (res.status == 200) {
					//循环遍历json，并将其加入显示中
					//alert("退出登录成功！");
						window.location.href="/login.html";
				} else
					alert("退出登录失败！");
			},
			error : function(xml, err, throwInfo) {
				alert(err);
			}
	    });	
	});
	
	 
    $('#topic-submit').click(function(){
        //向服务端发送请求，此处需要后台返回接送json数据，包括id
    	var root = $('#definition').val();
    	var content ={
    			 "meta":{"name":"demo","author":"zhangyipin","version":"0.2"},
    			 "format":"node_array",
    			 "data":[
    			         {"id":"0","topic":"new","expanded":true,"isroot":true,"root":true}
    			      ]};  
    	for(var i in content.data){
    		content.data[i].topic=root;	
    	}
    	var strcontent=JSON.stringify(content);
    	//alert(strcontent);
    	var jsondata = {
			"root" : root,
			"account_id":account_id,
			"content":strcontent,
			"state":"0",
			"type":"0"
		};
		$.post("/schems",jsondata).success(function(res) {
			if (res.status == 200) {
				addRootDiv(res.data.id,res.data.root);
				$('#treeview5').treeview(true).root_terms_add(res.data.id,res.data.root);
			} else
				alert("添加新任务失败");
		}).error(function(xml, err, throwInfo) {
			alert(err);
		});
    });
    $('#show-tree').click(function(event){
		var hidebg=document.getElementById('hidebg');
    	if(!treeshow_bool){
    		$('#left-bar')[0].style.display="block";
    		treeshow_bool=true;
    	  	hidebg.style.display="block";
    	}else{
    		$('#left-bar')[0].style.display="";
    		treeshow_bool=false;
    		hidebg.style.display="none";
    	}
    });
	$('#hidebg').click(function(event){
		$('#left-bar')[0].style.display="";
		treeshow_bool=false;
		hidebg.style.display="none";
	});
    $('#file-submit').click(function(){
        //向服务端发送请求，此处需要后台返回接送json数据，包括id
    	var file_name = $('#definitionforf').val();
    	
    	var jsondata = {
			"name":file_name,
			"account_id":account_id,
			"state":"0",
			"type":"0"
		};
		$.post("/files",jsondata).success(function(res) {
			if (res.status == 200) {
				addFileDiv(res.data.id,res.data.text);
				
				$('#treeview5').treeview(true).root_files_add(res.data.id,res.data.text);
				getTree();
			}else if(res.status == 400){
				alert("最多建立五层文件结构");
			}else
				alert("添加新任务失败");
		}).error(function(xml, err, throwInfo) {
			alert(err);
		});
    });
   
    $(window).resize(function(){
    	//alert($(window).height()-$("#term-show").offset().top);
    	//selfresize();
    	
    });
    $('#searchtext').keydown(function(event){
    	if(event.keyCode==13){
    		var searchtext=document.getElementById('searchtext');
    		var defini=searchtext.value;
    		
    		var ss=document.getElementById('searchresultall');
			var childs=ss.childNodes;
			if(!!childs){
				for(var i=childs.length-1;i>=0;i--){    
					ss.removeChild(childs.item(i));    
				}   
			}
			if(!!!defini){
	  			ss.style.display='none';
	  			return;
	  		}
	  		ss.style.display='';
			
    		$.ajax({
				type : 'GET',
				url : '/terms/search',
			    cache: false,
				async:false,
				data :{
					"definition":defini
				},
				//timeout:7000,//请求超时后停止请求
				dataType : 'json',
				//contentType: "application/json; charset=utf-8",
				success : function(res) {
					if (res.status == 200) {
						for(var kk in res.entries){
							//alert(res.entries[kk].definition+"+"+res.entries[kk].id);
							
							addSearchDivForM(res.entries[kk].id,res.entries[kk].definition);
						}
					} else
						alert("添加新任务失败");
				},
				error : function(xml, err, throwInfo) {
					alert(err);
				}
        	});
    		
    		$.ajax({
				type : 'GET',
				url : '/schems/search',
			    cache: false,
				async:false,
				data :{
					"root":defini,
					"type":'1',
					"state":'1'
				},
				//timeout:7000,//请求超时后停止请求
				dataType : 'json',
				//contentType: "application/json; charset=utf-8",
				success : function(res) {
					if (res.status == 200) {
						for(var kk in res.entries){
							//alert(res.entries[kk].definition+"+"+res.entries[kk].id);
							
							addSearchDivForP(res.entries[kk].id,res.entries[kk].root);
						}
				
					} else
						alert("添加新任务失败");
				},
				error : function(xml, err, throwInfo) {
					alert(err);
				}
        	});
    		
    		
    	} 
    });
    
    
    $('#searchresultall').mouseleave(function(){
    	//this.style.display="none"
    });
    
    $('#searchtext').blur(function(){
    	var icon=document.getElementById('icon');
    	var searchtext=document.getElementById('searchtext');
    	var searchbtn=document.getElementById('topic-search');
    });
    
    function addSearchDivForM(id,definition){
    	var sra=document.getElementById('searchresultall');
    	
    	var newresult=document.createElement('div');
    	newresult.setAttribute("id","msearchresult-"+id);
    	newresult.setAttribute("class","searchresult");
    	newresult.innerHTML="素材库"+id.toString()+"+"+definition;
    	sra.appendChild(newresult);
    	sra.style.display="";
    	$('#msearchresult-'+id).click(function(){
    		if(typeof id=== "string"){
    			alert('string');
    		}
    		var searchroot =Number(id);
			
			$.ajax({
				type : 'GET',
				url : '/terms/roots/search',
			    cache: false,
				async:false,
				data :{
					"searchroot":searchroot
				},
				//timeout:7000,//请求超时后停止请求
				dataType : 'json',
				contentType: "application/json; charset=utf-8",
				success : function(data) {
					if (data.status == 200) {
						window.location.href="/user/selfpmtreat.html";
					} else
						alert("添加新任务失败");
				},
				error : function(xml, err, throwInfo) {
					alert(err);
				}
        	});
    	});
    }
    function addSearchDivForP(id,definition){
    	var sra=document.getElementById('searchresultall');
    	
    	var newresult=document.createElement('div');
    	newresult.setAttribute("id","psearchresult-"+id);
    	newresult.setAttribute("class","searchresult");
    	newresult.innerHTML="方案库"+id.toString()+"+"+definition;
    	sra.appendChild(newresult);
    	sra.style.display="";
    	$('#psearchresult-'+id).click(function(){

    		if(typeof id=== "string"){
    			alert('string');
    		}
    		var searchroot =Number(id);
			
			$.ajax({
				type : 'GET',
				url : '/schems/roots/search',
			    cache: false,
				async:false,
				data :{
					"searchroot":searchroot,					
				},
				//timeout:7000,//请求超时后停止请求
				dataType : 'json',
				contentType: "application/json; charset=utf-8",
				success : function(data) {
					if (data.status == 200) {
						window.location.href="/user/selfpptreat.html";
					} else
						alert("添加新任务失败");
				},
				error : function(xml, err, throwInfo) {
					alert(err);
				}
        	});
    	});
    }
	//添加新任务时在前端显示,id为整数即可，不用类型转换
    function addRootDiv(id,definition){
    	//alert(definition);
		var ts=document.getElementById('term-show');
    	var newterm=document.createElement('div');
		newterm.setAttribute("id","term-"+id);
		newterm.setAttribute("class","term-root");
		
		
		var newterm_picture=document.createElement('div'); 
		newterm_picture.setAttribute("class","file-picture");
		newterm_picture.innerHTML="<img src='../image/term-root.png' style='width:100%;'>";
		

		var newterm_name=document.createElement('div'); 
		newterm_name.innerHTML="<span "+'id="rename-definition-'+id+'">'+definition+"</span>";	
		newterm_name.setAttribute("class","term-root-name");
		
		var newterm_solve=document.createElement('div'); 
		newterm_solve.setAttribute("class","term-root-solve");
		
		var renamebtn=document.createElement('div'); 
		
		if(window.location.pathname=='/admin/selfmlib.html'){
			renamebtn.innerHTML="<span class='glyphicon glyphicon-repeat' id='rename-"+id.toString()+"'>重命名</span>";
		}
		renamebtn.setAttribute("id","term-rename-"+id);
		renamebtn.setAttribute("class","term-root-delete");
		renamebtn.style.display="none";
		
		
		var submitmbtn=document.createElement('div'); 
		
		if(window.location.pathname=='/admin/selfmlib.html'){
			submitmbtn.innerHTML="<span class='glyphicon glyphicon-open' id='submitm-"+id.toString()+"'>提交</span>";
		}
		submitmbtn.setAttribute("id","term-submit-"+id);
		submitmbtn.setAttribute("class","term-root-delete");
		submitmbtn.style.display="none";
		
		
		var deletebtn=document.createElement('div');
		
		if(window.location.pathname=='/admin/selfmlib.html'){
			deletebtn.innerHTML="<span class='glyphicon glyphicon-trash' id='delete-"+id.toString()+"'>删除</span>";
		}
		deletebtn.setAttribute("id","term-delete-"+id);
		deletebtn.setAttribute("class","term-root-delete");
		deletebtn.style.display="none";
		
		newterm.appendChild(newterm_picture);
		newterm.appendChild(newterm_name);
		
		if(renamebtn_bool){
			newterm_solve.appendChild(renamebtn);
		}
		if(submitmbtn_bool){
			newterm_solve.appendChild(submitmbtn);
		}
		if(deletebtn_bool){
			newterm_solve.appendChild(deletebtn);
		}
		newterm_solve.style.marginTop="-10px";
		newterm.appendChild(newterm_solve);
		
		ts.appendChild(newterm);
		
		var rootNodeW=false;
		document.getElementById('term-'+id.toString()).addEventListener('touchstart', function(e) {
			 e.preventDefault();
			 rootNodeW=false;
			 timeout = setTimeout(function(){
				 
				 renamebtn.style.display="";
				 submitmbtn.style.display="";
				 deletebtn.style.display="";
				 rootNodeW=true;
                 return;
             }, 500);
		});
		document.getElementById('term-'+id.toString()).addEventListener('touchmove', function(e) {
			clearTimeout(timeout);
			rootNodeW=true;
		});
		document.getElementById('term-'+id.toString()).addEventListener('touchend', function(e) {
			
			clearTimeout(timeout); 
			if(!rootNodeW){
				$('#term-'+id.toString()).click();
			}
		});
		document.getElementById('term-delete-'+id.toString()).addEventListener('touchstart', function(e) {
			e.preventDefault();
			$('#term-delete-'+id.toString()).click();
			e.stopPropagation();
		});
		document.getElementById('term-submit-'+id.toString()).addEventListener('touchstart', function(e) {
			e.preventDefault();
			$('#term-submit-'+id.toString()).click();
			e.stopPropagation();
		});
		$('#term-'+id.toString()).click(function(){
		
			var root = id;
		
			$.ajax({
				type : 'GET',
				url : '/schems/roots/select',
			    cache: false,
				async:false,
				data :{
					"selfrootId":root
				},
				//timeout:7000,//请求超时后停止请求
				dataType : 'json',
				contentType: "application/json; charset=utf-8",
				success : function(data) {
					if (data.status == 200) {
						if(window.location.pathname=='/user/selfplib.html'){
							window.location.href="/user/selfmtreat.html";
						}else{
							window.location.href="/admin/selfmtreat.html";
						}
					} else
						alert("添加新任务失败");
				},
				error : function(xml, err, throwInfo) {
					alert(err);
				}
        	});
		});

		$('#term-'+id.toString()).mousedown(function(e){
			if(3==e.which){
				submitmbtn.style.display="";
				renamebtn.style.display="";
				
				deletebtn.style.display="";
			}
		});	
		
		$('#term-'+id.toString()).mouseleave(function(){
			//if(show_id!=null){
			submitmbtn.style.display="none";
			renamebtn.style.display="none";
			deletebtn.style.display="none";	
		});
		
		$('#term-submit-'+id.toString()).click(function(){
			$('#submit-file').modal('show');
			$('#submit-term-id')[0].innerHTML=id;
			return false;
		});
		$('#term-rename-'+id.toString()).click(function(){
			$('#renameTerm').modal('show');
			$('#submit-term-id')[0].innerHTML=id;
			$('#rename-definition')[0].value =$('#rename-definition-'+id.toString())[0].innerHTML;
			return false;
		});
		$('#term-delete-'+id.toString()).click(function(){
		//向后端发送删除请求
			//var deleteterm=document.createElementById('#term-delete-'+id.toString());
			$.ajax({
				type: 'DELETE',
			    url: '/schems/' + id.toString()+'/delete',
			      //data : selected_id,
			    async:false,
			    timeout: 7000,//请求超时后停止请求
			    dataType: 'json',
			    success: function (data) {
			    	if (data.status == 200) {
			    		ts.removeChild(newterm);
			    		$('#treeview5').treeview(true).root_terms_delete(id);
			    	} else {
			    		alert("删除失败");
			        }
			    },
			    error: function (xml, err, throwInfo) {
			    	alert(err);
			    }
			});

			return false;
		});
		
		$('#term-'+id.toString()).bind("contextmenu", function(){
			return false;
		});
		
		//点击任务按钮，进行跳转，到绘制思维导图界面
    }
    //待改
    function addFileDiv(id,name){
    	//alert(definition);
		var ts=document.getElementById('term-show');
    	var newterm=document.createElement('div');
		newterm.setAttribute("id","file-"+id);
		newterm.setAttribute("class","term-root");
		
		var newterm_solve=document.createElement('div'); 
		newterm_solve.setAttribute("class","term-root-solve");
		
		var newterm_picture=document.createElement('div'); 
		newterm_picture.setAttribute("class","file-picture");
		newterm_picture.innerHTML="<img src='../image/file.png' style='width:100%;'>";
		
		
		var renamebtn=document.createElement('div'); 
		if(window.location.pathname=='/admin/selfmlib.html'){
			renamebtn.innerHTML="<span class='glyphicon glyphicon-repeat' id='rename-"+id.toString()+"'>重命名</span>";
		}
		renamebtn.setAttribute("id","file-rename-"+id);
		renamebtn.setAttribute("class","term-root-delete");
		renamebtn.style.display="none";
		
		
		var deletebtn=document.createElement('div');
		if(window.location.pathname=='/admin/selfmlib.html'){
			deletebtn.innerHTML="<span class='glyphicon glyphicon-trash' id='delete-"+id.toString()+"'>删除</span>";
		}
		deletebtn.setAttribute("id","file-delete-"+id);
		deletebtn.setAttribute("class","term-root-delete");
		deletebtn.style.display="none";
		
		var newterm_name=document.createElement('div'); 
		newterm_name.innerHTML="<span "+'id="rename-file-definition-'+id+'">'+name+"</span>";	
		
		newterm_name.setAttribute("class","term-root-name");
		
		newterm.appendChild(newterm_picture);
		newterm.appendChild(newterm_name);
		if(renamebtn_bool){
			newterm_solve.appendChild(renamebtn);
		}
		if(deletebtn_bool){
			newterm_solve.appendChild(deletebtn);
		}
		newterm.appendChild(newterm_solve);
		ts.appendChild(newterm);
		$('#file-'+id.toString()).click(function(){
			$("#term-show")[0].innerHTML="";
			getRoots(id);
		});
		$('#file-'+id.toString()).mousedown(function(e){
			if(3==e.which){
				renamebtn.style.display="";
				deletebtn.style.display="";
			}
		});	
		
		$('#file-'+id.toString()).mouseleave(function(){
			renamebtn.style.display="none";
			deletebtn.style.display="none";	
		});
		$('#file-rename-'+id.toString()).click(function(){
			$('#renameFile').modal('show');
			$('#submit-term-id')[0].innerHTML=id;
			$('#rename-file-definition')[0].value =$('#rename-file-definition-'+id.toString())[0].innerHTML;
			return false;
		});
		$('#file-delete-'+id.toString()).click(function(){
			//向后端发送删除请求
				//var deleteterm=document.createElementById('#term-delete-'+id.toString());
			$.ajax({
				type: 'DELETE',
				url: '/files/' + id.toString(),
				async:false,
				timeout: 7000,//请求超时后停止请求
				dataType: 'json',
				success: function (data) {
				   if (data.status == 200) {
					   ts.removeChild(newterm);
					   $('#treeview5').treeview(true).root_files_delete(id);
				   } else {
					   alert("删除失败");
				   }
				 },
				  error: function (xml, err, throwInfo) {
				    alert(err);
				  }
			});
			return false;
		});
		$('#file-'+id.toString()).bind("contextmenu", function(){
			return false;
		});
    }
    
    /*
    function selfresize(){
    	//if(window.location.pathname=='/admin/selfmlib.html'){

	  	$('#searchresultall').css('max-height',$(window).height()-$("#term-show").offset().top+'px');	
    	//alert($("#searchresultall").offset().top);
    	if($(window).width()<450){
  
    		$('#function-bar').css('top','0px');
    		$('#toolicon').css('margin-left','8px');
    		$('#user-message').css('margin-right','20px');
    		$('#toolbar').css('margin-right','20px');

    		$('#left-bar').width('98%');
    		$('#left-bar').css('margin-top','30px');
    		$('#term-show').width('98%');
    		
    		if(window.location.pathname=='/user/selfplib.html'){
    			$('#term-show').css('margin-top','70px');
    			$('#toolicon').css('margin-left','8px');
    			$('#searchtext').css('width','90px');
    			$('#searchdiv').css('width','10px');
    			$('#searchbar').css('margin-right','30px');
    			$('#toolicon').css('font-size','8px');
    			$('#topic-mind').css('font-size','25px');
    			
    		}else{
    			$('#term-show').css('margin-top','9px');
    		}
    		
    		$('#term-show').css('min-height',$(window).height()-$("#term-show").offset().top+'px');
    		
    	
    	}else if($(window).width()<697){
    		//alert($(window).width());
    		$('#function-bar').css('top','10px');
    		$('#toolicon').css('margin-left','80px');
    		$('#user-message').css('margin-right','20px');
    		$('#toolbar').css('margin-right','20px');
    		
    		$('#left-bar').width('98%');
    		$('#left-bar').css('margin-top','50px');
    		
    		$('#term-show').width('98%');
    		if(window.location.pathname=='/user/selfplib.html'){
    			$('#term-show').css('margin-top','80px');
    			$('#toolicon').css('margin-left','8px');
    			$('#searchtext').css('width','100px');
    			$('#searchdiv').css('width','10px');
    			$('#searchbar').css('margin-right','50px');
    			$('#topic-mind').css('font-size','35px');
    			
    		}else{
    			$('#term-show').css('margin-top','9px');
    		}
    		
    		$('#term-show').css('min-height',$(window).height()-$("#term-show").offset().top+'px');
    		
    		
    	}else{
    		$('#function-bar').css('top','30px');
    		$('#toolicon').css('margin-left','80px');
    		$('#user-message').css('margin-right','80px');
    		$('#toolbar').css('margin-right','80px');
    		
    		$('#left-bar').width('10%');
    		$('#left-bar').css('margin-top','130px');
    		
    		$('#term-show').width('83%');
    		if(window.location.pathname=='/user/selfplib.html'){
    			$('#searchdiv').css('width','100px');
    			$('#searchtext').css('width','200px');
    			$('#searchbar').css('margin-right','80px');
    			$('#topic-mind').css('font-size','35px');
    		}else{
    			
    		}
    		$('#term-show').css('margin-top','90px');
    		$('#term-show').css('min-height',$(window).height()-$("#term-show").offset().top-50+'px');
    	}
    	//}
    }
    */
});
